﻿
@{
    ViewData["Title"] = "员工首页";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
}
@section styles
    {
    <environment names="Development">
        <link href="~/css/plugins/jqgrid/ui.jqgrid.css" rel="stylesheet" />
    </environment>
    <environment names="Staging,Production">
        <link rel="stylesheet" href="~/css/grid.min.css" asp-append-version="true" />
    </environment>
    <link href="~/js/plugins/select2/css/select2.css" rel="stylesheet" />
}

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>员工管理</h5>
           
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <form enctype="multipart/form-data" id="uploadForm" asp-controller="Xlsx" asp-action="Import" method="post">

                <div class="row">
                    <div class="col-sm-1"><button id="btnAdd" type="button" class="btn btn-primary " onclick="addModel()"><i class="fa fa-check"></i>&nbsp;添加</button></div>
                    <div class="col-sm-1"><button id="btnEdit" type="button" class="btn btn-info " onclick="editModel()"><i class="fa fa-paste"></i> 编辑</button></div>
                    <div class="col-sm-1">
                        <button id="btnDel" type="button" class="btn btn-danger " onclick="delData()">
                            <i class="fa fa-dedent"></i>&nbsp;<span class="bold">删除</span>
                        </button>
                    </div>
                    <div class="col-sm-2">
                        <button id="btnPaiban" type="button" class="btn btn-danger " onclick="upPaiban()">
                            <i class="fa fa-dedent"></i>&nbsp;&nbsp;<span class="bold">排班修改</span>
                        </button>
                    </div>
                    <div class="col-sm-1">
                        <button class="btn btn-success fileinput-button" type="button">Excel上传</button>
                        <input type="file" id="excelfile" onchange="doUpload()" name="excelfile" style="position:absolute;top:0;left:0;font-size:34px; opacity:0">
                        @*<input type="file" onchange="doUpload()" id="excelfile" name="excelfile" class="btn btn-info" value="Excel上传" />*@
                    </div>
                </div>

                <div class="form-group">
                    @*<table style="width:60%;">
                            <tr>

                                <td><button id="btnAdd" type="button" class="btn btn-primary " onclick="addModel()"><i class="fa fa-check"></i>&nbsp;添加</button></td>
                                <td width='10px'>&nbsp;</td>
                                <td><button id="btnEdit" type="button" class="btn btn-info " onclick="editModel()"><i class="fa fa-paste"></i> 编辑</button></td>
                                <td width='10px'>&nbsp;</td>
                                <td>
                                    <button id="btnDel" type="button" class="btn btn-danger " onclick="delData()">
                                        <i class="fa fa-dedent"></i>&nbsp;<span class="bold">删除</span>
                                    </button>
                                </td>
                                <td width='10px'>&nbsp;</td>
                                <td>
                                    <button id="btnPaiban" type="button" class="btn btn-danger " onclick="upPaiban()">
                                        <i class="fa fa-dedent"></i>&nbsp;&nbsp;<span class="bold">排班修改</span>
                                    </button>
                                </td>
                                <td width='10px'>&nbsp;</td>
                                <td>
                                    <input type="file" onchange="doUpload()" id="excelfile" name="excelfile" class="btn btn-info" value="Excel上传" />
                                </td>
                            </tr>
                        </table>

                        <button id="btnStop" type="button" class="btn btn-danger " onclick="delStop()">
                <i class="fa fa-dedent"></i>&nbsp;&nbsp;<span class="bold">停用</span>
            </button>




                          <button id="btnSetRole" type="file" class="btn btn-info "><i class="fa fa-user"></i>导出excel</button>*@
                </div>
            </form>
                <div class="form-group">
                    <div class="row">
                        <div class="col-md-3"> <input id="txtSearchKey" type="text" class="input form-control" placeholder="员工姓名" /></div>
                        <div class="col-md-3"> <input id="JobPositionName" type="text" class="input form-control" placeholder="岗位名称" /></div>
                        <!--
    <div class="col-md-3">
        <select id="PositionTypeId" name="PositionTypeId" class="form-control"></select>
    </div>-->
                        <div class="col-md-3">
                            <span class="input-group-btn">
                                <button id="btnSearch" class="btn btn btn-primary" type="button"> <i class="fa fa-search"></i> 搜索</button>

                            </span>
                        </div>

                    </div>
                </div>

                <div class="jqGrid_wrapper">
                    <table id="table_list"></table>
                    <div id="pager_list"></div>
                </div>
        </div>
        </div>
</div>

@section scripts
    {
        <script src="~/js/plugins/jqgrid/jquery.jqGrid.js"></script>
        <script src="~/js/plugins/jqgrid/i18n/grid.locale-cn.js"></script>
        <script src="~/js/jqgrid-list.js"></script>
        <script src="~/js/json2.js"></script>
        <script src="~/js/base.js"></script>
    <environment names="Staging,Production">
        <script src="~/js/grid.min.js" asp-append-version="true"></script>
        <script src="~/js/validate.min.js" asp-append-version="true"></script>
        <script src="~/js/base.min.js" asp-append-version="true"></script>
    </environment>
    <script src="~/js/plugins/select2/js/select2.js"></script>
    <script src="~/js/BindSelect.js"></script>
    <script>
        function addModel() {
            $("#btnAdd").button("loading");
            window.location.href = "@Url.Action("Add")";
        }

        function upPaiban() {
            var row = JucheapGrid.GetData();
                var row = JucheapGrid.GetData();
            if (row != null) {
                $("#btnEdit").button("loading");
                window.location.href = "@Url.Action("Edit")/" + row.id;
            } else {
                alert("请选择要排班的数据");
            }
            window.location.href = "/PaiBan/UpdateWorker?workerId=" + row.id;
        }

        @*$(function() {
             $('#PositionTypeId').select2({
                placeholder: "所属机构",
                ajax: {
                   url: '@Url.Action("GetJobPositionTypes", "JobPositionType")',
                    dataType: 'json'
                }
            });
        });*@

        function doUpload() {
            var formData = new FormData($("#uploadForm")[0]);
            $.ajax({
                url: "/Xlsx/Import",
                //beforeSend: function (xhr) {
                //    xhr.setRequestHeader("XSRF-TOKEN",
                //        $('input:hidden[name="__RequestVerificationToken"]').val());
                //},
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    alert("上传成功");
                    //$("#imgUserHeadImageUrl").attr('src', '/upload/' + returndata);
                    //$("#IdentificationHeadImageUrl").val(returndata);
                    window.location.reload();
                },
                error: function (returndata) {
                }
            });
        }


        BindSelect("PositionTypeId", "/JobPositionType/GetJobPositionTypes");
        function editModel() { //编辑
            var row = JucheapGrid.GetData();
            if (row != null) {
                $("#btnEdit").button("loading");
                window.location.href = "@Url.Action("Edit")/" + row.id;
            } else {
                alert("请选择要编辑的数据");
            }
        }

        function delData() { //删除
            XPage.DelData("@Url.Action("Delete")");
        }

       

           function delStop() { //删除
            XPage.DelData("@Url.Action("Stop")");
        }

        function searchData() { //搜索
            var json = {
                name: $("#txtSearchKey").val(),
                JobPositionTypeId: $("#PositionTypeId").val(),
                jobPositionName: $("#JobPositionName").val(),
            };
            XPage.Search(json);
        }

        $(document).ready(function() {
            var config = {
                title: '用户列表',
                url: '@Url.Action("GetListWithPager")',
                colNames: ['序号', '姓名', '公司名称',  '岗位名称', '身份证号', ],
                colModel: [
                    { name: 'id', index: 'id', width: 60, key: true, hidden: true },
                    { name: 'name', index: 'name', width: 60 },
                    { name: 'companyName', index: 'companyName', width: 60 },
                    { name: 'jobPositionName', index: 'jobPositionName', width: 60 },
                    { name: 'cardNumber', index: 'cardNumber', width: 60 },
                ]
            };
            JucheapGrid.Load(config);
            $("#btnSearch").bind("click", searchData);

        });
    </script>
}
